$(function () {

    const tag = 'xxx'
    const socket = io();
    var nickname ;

    $(".trigger_popup_fricc").click(function(){
       $('.hover_bkgr_fricc').show();
    });
    $('.hover_bkgr_fricc').click(function(){
        //$('.hover_bkgr_fricc').hide();
    });
    $('.popupCloseButton').click(function(){
	nickname = $('#nickname').val()
	if(empty(nickname)){
	    $('#hint').text("Invalid nick name!!!!!!!");
	    return
	}

        $('.hover_bkgr_fricc').hide();
    });

    $('form').submit(function(e) {
	e.preventDefault(); // prevents page reloading
	let input = $('#m').val()
	if(empty(input))
	   return
	const msgStr = nickname + ': ' + input
	const msg = {src: nickname, txt: input}
	$('#messages').prepend($('<li>').text(msgStr));
	socket.emit(tag, JSON.stringify(msg));
	$('#m').val('');
	return false;
    });
    socket.on(tag, function(msg){
	$('#messages').prepend($('<li>').text(msg));
    });
    socket.on('connect', function() {
	/*
	if(prompt){
	    do{
		nickname = prompt("Please enter your nick name", "Harry Potter");
	    }while(nickname == undefined || nickname == null || nickname.length == 0)
	}
	*/
	socket.emit('join', nickname);
    });
});
